import {
  BasePickInputProps,
  PickInputValueType,
} from '@app-cad/common/components/pick-input/types';

export function getPickOptions(
  allowPickType: BasePickInputProps['allowPickType'],
  disallowedPickType: BasePickInputProps['disallowedPickType'],
) {
  let allowVertex = allowPickType.includes(PickInputValueType.Vertex);
  let allowPlane = allowPickType.includes(PickInputValueType.Plane);
  let allowSurface = allowPickType.includes(PickInputValueType.Surface);
  let allowLine = allowPickType.includes(PickInputValueType.Line);
  let allowCurve = allowPickType.includes(PickInputValueType.Curve);
  let allowModel = allowPickType.includes(PickInputValueType.Model);
  let allowALL = allowPickType.includes(PickInputValueType.ALL);
  let allowSketch = allowPickType.includes(PickInputValueType.Sketch);
  let allowFrame = allowPickType.includes(PickInputValueType.Frame);
  let allowProduct = allowPickType.includes(PickInputValueType.Product);
  let allowFullProduct = allowPickType.includes(PickInputValueType.FullProduct);
  let allowLawCurve = allowPickType.includes(PickInputValueType.LawCurve);
  let allowPartArray = allowPickType.includes(PickInputValueType.PartArray);
  const allowTempFace = allowPickType.includes(PickInputValueType.TempFace);

  if (Array.isArray(disallowedPickType) && disallowedPickType.length > 0) {
    allowVertex =
      allowVertex ||
      (allowALL && !disallowedPickType.includes(PickInputValueType.Vertex));
    allowPlane =
      allowPlane ||
      (allowALL && !disallowedPickType.includes(PickInputValueType.Plane));
    allowSurface =
      allowSurface ||
      (allowALL && !disallowedPickType.includes(PickInputValueType.Surface));
    allowLine =
      allowLine ||
      (allowALL && !disallowedPickType.includes(PickInputValueType.Line));
    allowCurve =
      allowCurve ||
      (allowALL && !disallowedPickType.includes(PickInputValueType.Curve));
    allowModel =
      allowModel ||
      (allowALL && !disallowedPickType.includes(PickInputValueType.Model));
    allowSketch =
      allowSketch ||
      (allowALL && !disallowedPickType.includes(PickInputValueType.Sketch));
    allowFrame =
      allowFrame ||
      (allowALL && !disallowedPickType.includes(PickInputValueType.Frame));
    allowProduct =
      allowProduct ||
      (allowALL && !disallowedPickType.includes(PickInputValueType.Product));
    allowFullProduct =
      allowFullProduct ||
      (allowALL &&
        !disallowedPickType.includes(PickInputValueType.FullProduct));
    allowLawCurve =
      allowLawCurve ||
      (allowALL && !disallowedPickType.includes(PickInputValueType.LawCurve));
    allowPartArray =
      allowPartArray ||
      (allowALL && !disallowedPickType.includes(PickInputValueType.PartArray));

    allowALL = disallowedPickType.length === 0;
  }
  return {
    allowVertex,
    allowPlane,
    allowSurface,
    allowLine,
    allowCurve,
    allowModel,
    allowALL,
    allowSketch,
    allowFrame,
    allowProduct,
    allowFullProduct,
    allowLawCurve,
    allowTempFace,
    allowPartArray,
  };
}
